package com.ucomm.talent.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import com.ucomm.talent.AppConfig;
import com.ucomm.talent.R;
import com.ucomm.talent.adapter.JobOffersListAdapter.ViewHolder;
import com.ucomm.talent.model.JobOfferInfo;
import com.ucomm.talent.model.RecommendedJobsInfo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: Vita Hao
 * Date: 13-5-24
 * Time: 下午2:59
 * To change this template use File | Settings | File Templates.
 */
public class RecommendJobsListAdapter extends BaseAdapter{

    private LayoutInflater mInflater;
    private ArrayList<RecommendedJobsInfo> mData;

    public RecommendJobsListAdapter(Context context, ArrayList<RecommendedJobsInfo> mData){
        this.mInflater = LayoutInflater.from(context);
        this.mData = mData;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int arg0) {
        return mData.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

    	ViewHolder holder = null;
        if (convertView == null) {

            holder=new ViewHolder();

            convertView = mInflater.inflate(R.layout.custom_list_item, null);
            holder.job_name = (TextView)convertView.findViewById(R.id.job_name);//职位名
            holder.certified_company = (TextView)convertView.findViewById(R.id.certified_company);
            holder.approval = (TextView)convertView.findViewById(R.id.approval);
            holder.work_category = (TextView)convertView.findViewById(R.id.work_category);//职位类别
            holder.work_location = (TextView) convertView.findViewById(R.id.work_location);//工作地点
            holder.work_treatment = (TextView) convertView.findViewById(R.id.work_treatment);//待遇
            holder.work_enterprise = (TextView) convertView.findViewById(R.id.work_enterprise);//公司名
            convertView.setTag(holder);

        }else {
            holder = (ViewHolder)convertView.getTag();
        }
        RecommendedJobsInfo info = mData.get(position);
        String work_category = null;
        String work_location = null;
        String work_treatment = null;
        String work_enterprise = null;
        String address = null;
        holder.job_name.setText(info.getName());
        if(AppConfig.jobMap.size() != 0 && AppConfig.cityMap.size() != 0 && AppConfig.comMap.size() != 0 && 
        		AppConfig.industryMap.size() != 0 && AppConfig.userMap.size() != 0){
        	//职位类别
        	work_category = AppConfig.jobMap.get(info.getJobSon());
        	//工作地点
        	work_location = AppConfig.cityMap.get(info.getProvinceId()+"") + AppConfig.cityMap.get(info.getCityId()+"");
        	//待遇
        	work_treatment = AppConfig.comMap.get(info.getSalary()+"");
        }
        holder.work_category.setText(work_category);
        //address = info.getProvinceId()+info.getCityId()+"";
        holder.work_location.setText(work_location);
        holder.work_treatment.setText(work_treatment);
        if(AppConfig.comName.size()!=0){
        	work_enterprise = AppConfig.comName.get(info.getuId()+"");
        }
        holder.work_enterprise.setText(work_enterprise);



        return convertView;
    }

    final class ViewHolder{
        public TextView job_name;
        public TextView certified_company;
        public TextView approval;
        public TextView work_category;
        public TextView work_location;
        public TextView work_enterprise;
        public TextView work_treatment;

    }

	public ArrayList<RecommendedJobsInfo> getmData() {
		// TODO Auto-generated method stub
		return (ArrayList<RecommendedJobsInfo>) mData;
	}
}
